package com.mzj.saas.mservice.bill.service;

import com.alibaba.fastjson.JSON;
import com.mzj.saas.commons.ApiData;
import com.mzj.saas.commons.ConvertUtils;
import com.mzj.saas.commons.KeyWorker;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.commons.vo.redis.TokenRedisVo;
import com.mzj.saas.mservice.bill.entity.HouseExpenseBillRule;
import com.mzj.saas.mservice.bill.entity.HouseExpenseOther;
import com.mzj.saas.mservice.bill.entity.HouseExpenseRuleRef;
import com.mzj.saas.mservice.bill.repository.HouseExpenseBillRuleRepository;
import com.mzj.saas.mservice.bill.repository.HouseExpenseOtherRepository;
import com.mzj.saas.mservice.bill.repository.HouseExpenseRuleRefRepository;
import com.mzj.saas.mservice.bill.vo.CreateBillRequestParamVO;
import com.mzj.saas.mservice.bill.vo.HouseExpenseBillRuleVO;
import com.mzj.saas.mservice.bill.vo.HouseExpenseRuleRefVO;
import com.mzj.saas.mservice.bill.vo.NewProjectVO;
import com.mzj.saas.mservice.community.entity.Community;
import com.mzj.saas.mservice.community.entity.CommunityBuild;
import com.mzj.saas.mservice.community.entity.CommunityBuildUnit;
import com.mzj.saas.mservice.community.repository.CommunityBuildRepository;
import com.mzj.saas.mservice.community.repository.CommunityBuildUnitRepository;
import com.mzj.saas.mservice.community.repository.CommunityRepository;
import com.mzj.saas.mservice.community.service.AppCommunityService;
import com.mzj.saas.mservice.contract.entity.Contract;
import com.mzj.saas.mservice.contract.repository.ContractRepository;
import com.mzj.saas.mservice.eligible.entity.DepartmentEnterpriseTagRef;
import com.mzj.saas.mservice.eligible.entity.DepartmentHierarchy;
import com.mzj.saas.mservice.eligible.repository.DepartmentEnterpriseTagRefRepository;
import com.mzj.saas.mservice.eligible.repository.DepartmentHierarchyRepository;
import com.mzj.saas.mservice.house.entity.House;
import com.mzj.saas.mservice.house.repository.HouseRepository;
import com.mzj.saas.redis.RedisService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 新的账单费用Service
 */
@Service
public class NewBillService {
    private static final Logger LOG = LoggerFactory.getLogger(NewBillService.class);

    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private RedisService redisService;
    @Autowired
    private HouseExpenseOtherRepository houseExpenseOtherRepository;
    @Autowired
    private HouseRepository houseRepository;
    @Autowired
    private HouseExpenseRuleRefRepository houseExpenseRuleRefRepository;
    @Autowired
    private HouseExpenseBillRuleRepository houseExpenseBillRuleRepository;
    @Autowired
    private AppCommunityService appCommunityService;
    @Autowired
    private DepartmentHierarchyRepository departmentHierarchyRepository;
    @Autowired
    private CommunityRepository communityRepository;
    @Autowired
    private CommunityBuildRepository communityBuildRepository;
    @Autowired
    private CommunityBuildUnitRepository communityBuildUnitRepository;
    @Autowired
    private ContractRepository contractRepository;
    @Autowired
    private DepartmentEnterpriseTagRefRepository departmentEnterpriseTagRefRepository;

    /**
     * 收费项目-列表展示
     *
     * @param accessToken 权限鉴定
     * @param pageNumber  当页面
     * @param pageSize    页数
     * @param vo          收费项目实体类
     * @return
     */
    public ResultBean<ApiData<NewProjectVO>> projectList(String accessToken, Integer pageNumber, Integer pageSize, NewProjectVO vo) {
        //记录操作日志
        LOG.info("NewBillService projectList accessToken={},pageNumber={},pageSize={}", accessToken, pageNumber, pageSize);
        //获取用户登录权限
        TokenRedisVo tokenRedisVo = redisService.findTokenVo(accessToken);
        //用户权限的鉴定
        if (tokenRedisVo == null) {
            return ResultBean.failedResultOfToken();
        }
        //查询所有数据
        String SQL = " select eo.* from saas_house_expense_other eo left join saas_department d on eo.org_id = d.id  ";
        String count = "select count(1) from saas_house_expense_other eo left join saas_department d on eo.org_id = d.id  ";

        //政府机构，根据区域标签所对应区域id查看
        Long enterpriseId = tokenRedisVo.getEnterpriseId();
        //根据用户ID查询出用户层级权限
        DepartmentHierarchy hierarchy = departmentHierarchyRepository.findByOrgIdAndStatus(enterpriseId, 1);
        if (hierarchy == null) {
            return ResultBean.failedResultWithMsg("用户所属机构未设置层级架构");
        }
        //查询机构层级关系ID
        Long id = hierarchy.getId();
        //获取机构层级关系信息
        List<DepartmentEnterpriseTagRef> refs = departmentEnterpriseTagRefRepository.findByDepRefId(id);
        //获取所有企业ID
        List<Long> enterpriseTagIds = refs.stream().map(DepartmentEnterpriseTagRef::getTagId).distinct().collect(Collectors.toList());//用户企业标签
        Long areaTagId = hierarchy.getTagId();//区域标签
        Long areaId = null;
        if (enterpriseTagIds.contains(3L)) {
            areaId = hierarchy.getAreaId();//区域id
        }
        //根据区域ID设置对应字段
        String areaTag = "";
        if (areaTagId == 1) {
            areaTag = "province_id";
        } else if (areaTagId == 2) {
            areaTag = "city_id";
        } else if (areaTagId == 3) {
            areaTag = "district_id";
        } else if (areaTagId == 4) {
            areaTag = "street_id";
        } else if (areaTagId == 5) {
            areaTag = "community_id";
        }

        List<Object> args = new ArrayList<>();
        StringBuilder where = new StringBuilder(" where 1=1 and eo.status = 1 and eo.type = 1  ");  // status 数据状态：1正常 2已删除

        if (enterpriseTagIds.contains(3L)) {
            where.append(" and (eo.org_id = ? or d." + areaTag + " = ? ) ");
            args.add(enterpriseId);
            args.add(areaId);

        } else {
            where.append(" and eo.org_id = ?  ");
            args.add(enterpriseId);
        }

        if (vo != null) {

            if (StringUtils.isNotBlank(vo.getName())) {
                where.append(" and eo.name like ?  ");
                args.add("%" + vo.getName() + "%");
            }
            if (StringUtils.isNotBlank(vo.getId())) {
                where.append(" and eo.id like ?  ");
                args.add("%" + vo.getId() + "%");
            }

        }

        ApiData<NewProjectVO> apiData = new ApiData<>();

        Long total = jdbcTemplate.queryForObject(count + where, Long.class, args.toArray());
        if (total == 0) {
            return ResultBean.successfulResult(apiData);
        }

        // 查询分页数据
        String offsets = " limit ? offset ?";
        where.append(" ORDER BY ").append(" eo.operator_time desc ").append(" \n").append(offsets);
        args.add(pageSize);
        args.add(pageNumber * pageSize);
        List<NewProjectVO> data = jdbcTemplate.query(SQL + where, new BeanPropertyRowMapper<>(NewProjectVO.class), args.toArray());
        //
        //设置总条数跟数据
        apiData.setTotal(total);
        apiData.setData(data);
        //把数据返回给前端页面
        return ResultBean.successfulResult(apiData);
    }

    //收费项目添加
    public ResultBean<Object> projectSave(String accessToken , NewProjectVO vo){
        LOG.info("NewBillService  projectSave  accessToken={} , vo={}", accessToken, JSON.toJSONString(vo));

        TokenRedisVo tokenRedisVo = redisService.findTokenVo(accessToken);
        if (tokenRedisVo == null) {
            return ResultBean.failedResultOfToken();
        }

        if(StringUtils.isBlank(vo.getName())){
            return ResultBean.failedResultWithMsg("项目名称为空");
        }

        if (StringUtils.isBlank(vo.getId())) {
            //新增操作
            List<HouseExpenseOther> projectList = houseExpenseOtherRepository.findByNameAndType(vo.getName(),1);
            if(projectList.size() > 0){
                return ResultBean.failedResultWithMsg("项目名称已存在");
            }

            HouseExpenseOther houseExpenseOther = new HouseExpenseOther();

            vo.setId("PJ" + KeyWorker.nextId());
            vo.setEnableStatus(0);
            vo.setStatus(1);
            String price = ConvertUtils.yuanToFen(String.valueOf(vo.getPrice()));
            vo.setOperatorId(tokenRedisVo.getId());
            vo.setOperatorTime(new Date());
            vo.setType(1); //类型：1公租房 2非公租房
            Long enterpriseId = tokenRedisVo.getEnterpriseId();
            vo.setOrgId(enterpriseId);

            BeanUtils.copyProperties(vo, houseExpenseOther);
            houseExpenseOther.setPrice(Integer.valueOf(price));
            houseExpenseOtherRepository.save(houseExpenseOther);

        }else{
            //修改操作
            HouseExpenseOther houseExpenseOther = houseExpenseOtherRepository.findById(vo.getId());
            if(houseExpenseOther == null ){
                return ResultBean.failedResultWithMsg("项目不存在");
            }
            if(!vo.getName().equals(houseExpenseOther.getName())){
                List<HouseExpenseOther> projectList = houseExpenseOtherRepository.findByNameAndType(vo.getName(),1);
                if(projectList.size() > 0){
                    return ResultBean.failedResultWithMsg("项目名称已存在");
                }
            }

            houseExpenseOther.setName(vo.getName());
            houseExpenseOther.setChargeMode(vo.getChargeMode());
            houseExpenseOther.setChargeType(vo.getChargeType());
            String price = ConvertUtils.yuanToFen(String.valueOf(vo.getPrice()));
            houseExpenseOther.setPrice(Integer.valueOf(price));
            houseExpenseOther.setUnit(vo.getUnit());

            houseExpenseOther.setOperatorId(tokenRedisVo.getId());
            houseExpenseOther.setOperatorTime(new Date());

            houseExpenseOtherRepository.save(houseExpenseOther);

        }
        return ResultBean.successfulResult(null);
    }

    /**
     * 收费项目-删除
     * @param accessToken 权限鉴定
     * @param id 项目id
     * @return
     */
    public ResultBean<Object> projectDelete(String accessToken, String id){
        //记录操作日志
        LOG.info("NewBillService  projectDelete  accessToken={} , id={}", accessToken, id);
        //根据项目ID查询收费项目信息
        HouseExpenseOther entity = houseExpenseOtherRepository.findById(id);
        //判断是否为空
        if(entity == null){
            return ResultBean.failedResultWithMsg("项目不存在");
        }
        //删除收费项目
        entity.setStatus(2);// status 数据状态：1正常 2已删除
        houseExpenseOtherRepository.save(entity);

        return ResultBean.successfulResult(null);
    }

    /**
     * 账单生成-生成账单
     * @param accessToken 权限鉴定
     * @param createBillRequestParamVO 创建账单对象
     * @return
     */
    public ResultBean<Object> createBill(String accessToken,CreateBillRequestParamVO createBillRequestParamVO){
        LOG.info("NewBillService  createBill  accessToken={} ", accessToken);
        //获取用户登录权限
        TokenRedisVo tokenRedisVo = redisService.findTokenVo(accessToken);
        //用户权限的鉴定
        if (tokenRedisVo == null) {
            return ResultBean.failedResultOfToken();
        }
        //获取前端传过来的账单数据
        HouseExpenseBillRuleVO ruleVO = createBillRequestParamVO.getHouseExpenseBillRuleVO();
        List<HouseExpenseRuleRefVO> ruleRefVO = createBillRequestParamVO.getHouseExpenseRuleRefVOS();
        Integer scope = ruleVO.getScope();
        //账单范围选择[ 1物业、2小区、3楼栋、4单元、5房号]，根据前端所选账单范围设置对应账单数据
        switch (scope){
            case 1:
                List<Long> housePropertyIds = ruleRefVO.stream().map(HouseExpenseRuleRefVO::getHousePropertyId).collect(Collectors.toList());
                List<House> houseList = houseRepository.findByHousePropertyIdIn(housePropertyIds);
                List<HouseExpenseRuleRefVO> refs = new ArrayList<>();
                for (House house : houseList) {
                    HouseExpenseRuleRefVO ref = new HouseExpenseRuleRefVO();
                    ref.setHouseNature(house.getHouseNature());
                    ref.setCommunityId(house.getResidenceCommunityId());
                    ref.setBuildingNum(house.getBuildingNum());
                    ref.setUnit(house.getUnit());
                    ref.setHouseId(house.getId());
                    refs.add(ref);
                }
                ruleRefVO = refs;
                break;
            case 2:
                List<String> residenceCommunityIds = ruleRefVO.stream().map(HouseExpenseRuleRefVO::getCommunityId).collect(Collectors.toList());
                List<House> houseList1 = houseRepository.findByResidenceCommunityIdIn(residenceCommunityIds);
                List<HouseExpenseRuleRefVO> refs1 = new ArrayList<>();
                for (House house : houseList1) {
                    HouseExpenseRuleRefVO ref = new HouseExpenseRuleRefVO();
                    ref.setHouseNature(house.getHouseNature());
                    ref.setCommunityId(house.getResidenceCommunityId());
                    ref.setBuildingNum(house.getBuildingNum());
                    ref.setUnit(house.getUnit());
                    ref.setHouseId(house.getId());
                    refs1.add(ref);
                }
                ruleRefVO = refs1;
                break;
            case 3:
                List<House> houseList2 =new ArrayList<>();
                for(HouseExpenseRuleRefVO ref : ruleRefVO){
                    String residenceCommunityId = ref.getCommunityId();
                    Long buildingNum = ref.getBuildingNum();
                    houseList2.addAll(houseRepository.findByResidenceCommunityIdAndBuildingNum(residenceCommunityId,buildingNum));
                }

                List<HouseExpenseRuleRefVO> refs2 = new ArrayList<>();
                for (House house : houseList2) {
                    HouseExpenseRuleRefVO ref = new HouseExpenseRuleRefVO();
                    ref.setHouseNature(house.getHouseNature());
                    ref.setCommunityId(house.getResidenceCommunityId());
                    ref.setBuildingNum(house.getBuildingNum());
                    ref.setUnit(house.getUnit());
                    ref.setHouseId(house.getId());
                    refs2.add(ref);
                }
                ruleRefVO = refs2;
                break;
            case 4:
                List<House> houseList3 =new ArrayList<>();
                for (HouseExpenseRuleRefVO ref : ruleRefVO) {
                    String residenceCommunityId = ref.getCommunityId();
                    Long buildingNum = ref.getBuildingNum();
                    Long unit = ref.getUnit();
                    houseList3.addAll(houseRepository.findByResidenceCommunityIdAndBuildingNumAndUnit(residenceCommunityId, buildingNum, unit));
                }
                List<HouseExpenseRuleRefVO> refs3 = new ArrayList<>();
                for (House house : houseList3) {
                    HouseExpenseRuleRefVO ref = new HouseExpenseRuleRefVO();
                    ref.setHouseNature(house.getHouseNature());
                    ref.setCommunityId(house.getResidenceCommunityId());
                    ref.setBuildingNum(house.getBuildingNum());
                    ref.setUnit(house.getUnit());
                    ref.setHouseId(house.getId());
                    refs3.add(ref);
                }
                ruleRefVO = refs3;
                break;
        }
        //获取标识：1前 2后
        Integer flag = ruleVO.getFlag();
        Integer day = ruleVO.getDay();
        Date startTimes = ruleVO.getStartTime();
        Integer dateFlag = ruleVO.getDateFlag();//时间标志：1开始时间 2结束时间
        if(dateFlag != null && dateFlag.equals(2)){
            startTimes = ruleVO.getEndTime();

        }
        Date closeTime = null;

        //判断前端传过来的标识
        if (flag.equals(1)) {  // 1前 2后
            Calendar cal = Calendar.getInstance();
            cal.setTime(startTimes);
            cal.add(Calendar.DAY_OF_MONTH, -day);
            closeTime = cal.getTime();
        } else {
            Calendar cal = Calendar.getInstance();
            cal.setTime(startTimes);
            cal.add(Calendar.DAY_OF_MONTH, day);
            closeTime = cal.getTime();
        }


        ruleVO.setCloseTime(closeTime);
        ruleVO.setType(1); //类型：1公租房 2非公租房
        //过滤掉非公租房
        List<HouseExpenseRuleRefVO> refs = new ArrayList<>();
        for(HouseExpenseRuleRefVO ref : ruleRefVO){
            if(ref.getHouseNature().equals(1)){
                refs.add(ref);
            }
        }
        ruleRefVO = refs;

        List<String> failRoomNumberList = new ArrayList<>(); //账单已存在的房号

        if(!ruleVO.getChargeType().equals(8)) {
            //验证账单周期
            for (HouseExpenseRuleRefVO houseExpenseRuleRefVO : ruleRefVO) {
                List<HouseExpenseRuleRef> existHouseExpenseRule = houseExpenseRuleRefRepository.findByHouseId(houseExpenseRuleRefVO.getHouseId());
                for (HouseExpenseRuleRef houseExpenseRuleRef : existHouseExpenseRule) {
                    HouseExpenseBillRule houseExpenseBillRule = houseExpenseBillRuleRepository.findById(houseExpenseRuleRef.getRuleId());
                    //时间段不能有交集
                    if (houseExpenseBillRule.getChargeType().equals(ruleVO.getChargeType())) {
                        if ((ruleVO.getStartTime().getTime() < houseExpenseBillRule.getStartTime().getTime() && ruleVO.getEndTime().getTime() >= houseExpenseBillRule.getStartTime().getTime())
                                || (ruleVO.getStartTime().getTime() >= houseExpenseBillRule.getStartTime().getTime() && ruleVO.getEndTime().getTime() <= houseExpenseBillRule.getEndTime().getTime())
                                || (ruleVO.getStartTime().getTime() <= houseExpenseBillRule.getEndTime().getTime() && ruleVO.getEndTime().getTime() > houseExpenseBillRule.getEndTime().getTime())) {
                            //return ResultBean.failedResultWithMsg("周期内账单已存在");
                            House house = houseRepository.findById(houseExpenseRuleRefVO.getHouseId()).get();
                            failRoomNumberList.add(house.getRoomNumber());
                        }
                    }
                }
            }

        }else{  //租金
            //验证账单存在
            for (HouseExpenseRuleRefVO houseExpenseRuleRefVO : ruleRefVO) {
                List<HouseExpenseRuleRef> existHouseExpenseRule = houseExpenseRuleRefRepository.findByHouseId(houseExpenseRuleRefVO.getHouseId());
                for (HouseExpenseRuleRef houseExpenseRuleRef : existHouseExpenseRule) {
                    HouseExpenseBillRule houseExpenseBillRule = houseExpenseBillRuleRepository.findById(houseExpenseRuleRef.getRuleId());
                    if (houseExpenseBillRule.getChargeType().equals(ruleVO.getChargeType())) {
                        //return ResultBean.failedResultWithMsg("押金账单已存在");
                        House house = houseRepository.findById(houseExpenseRuleRefVO.getHouseId()).get();
                        failRoomNumberList.add(house.getRoomNumber());
                    }
                }
            }

            /*
             * 1.公租房选择的房屋，验证公租房备案状态为：已备案 ；已备案的公租房，才有合同和承租人
             * 2.只生成已完成的合同设置的计费方式和收费项目的计费方式一致的房子的账单规则
             */
            List<HouseExpenseRuleRefVO> refList = new ArrayList<>();
            HouseExpenseOther expense = houseExpenseOtherRepository.findById(ruleVO.getExpenseId());
            for (HouseExpenseRuleRefVO ref : ruleRefVO) {
                House house = houseRepository.findById(ref.getHouseId()).get();
                if(house.getRecordStatus().equals(1)){ //0未备案 1已备案
                    List<Contract> contractList = contractRepository.findByHouseId(ref.getHouseId());
                    if(contractList.size() > 0){
                        Contract contract = contractList.get(0);
                        if(contract.getPayType().equals(expense.getChargeMode())){
                            refList.add(ref);
                        }
                    }
                }
            }

            ruleRefVO = refList;

        }

        //返回失败房号
        if (failRoomNumberList.size() > 0) {
            return ResultBean.failedResultWithMsg(failRoomNumberList.toString() + "：账单已存在，无法生成账单");
        }

        //无房屋则不生成
        if(ruleRefVO.size() == 0){
            return ResultBean.failedResultWithMsg("无房屋生成！");
        }

        //生成账单
        ruleVO.setId("ZD" + KeyWorker.nextId());
        ruleVO.setNumber(ruleRefVO.size());
        ruleVO.setOperatorId(tokenRedisVo.getId());
        ruleVO.setCreateTime(new Date());
        HouseExpenseBillRule houseExpenseBillRule = new HouseExpenseBillRule();
        BeanUtils.copyProperties(ruleVO, houseExpenseBillRule);

        HouseExpenseBillRule save = houseExpenseBillRuleRepository.save(houseExpenseBillRule);
        if (save != null) {
            List<HouseExpenseRuleRef> ruleRefList = new ArrayList<>();
           ruleRefVO.forEach(h -> {
                HouseExpenseRuleRef houseExpenseRuleRef = new HouseExpenseRuleRef();
                BeanUtils.copyProperties(h, houseExpenseRuleRef);
                houseExpenseRuleRef.setRuleId(save.getId());
               ruleRefList.add(houseExpenseRuleRef);
            });

            houseExpenseRuleRefRepository.saveAll(ruleRefList);
        }

        return ResultBean.successfulResult(null);
    }

    /**
     * 账单生成-编辑账单
     * @param accessToken 权限鉴定
     * @param createBillRequestParamVO 生成账单请求帮助类
     * @return
     */
    public ResultBean<Object> updateBill(String accessToken,CreateBillRequestParamVO createBillRequestParamVO){
        LOG.info("NewBillService  updateBill  accessToken={} ", accessToken);

        TokenRedisVo tokenRedisVo = redisService.findTokenVo(accessToken);
        if (tokenRedisVo == null) {
            return ResultBean.failedResultOfToken();
        }

        HouseExpenseBillRuleVO ruleVO = createBillRequestParamVO.getHouseExpenseBillRuleVO();
        List<HouseExpenseRuleRefVO> ruleRefVO = createBillRequestParamVO.getHouseExpenseRuleRefVOS();

        if(StringUtils.isBlank(ruleVO.getId())){
            return ResultBean.failedResultWithMsg("账单id为空");
        }

        Integer scope = ruleVO.getScope();
        //账单范围选择[ 1物业、2小区、3楼栋、4单元、5房号]
        switch (scope){
            case 1:
                List<Long> housePropertyIds = ruleRefVO.stream().map(HouseExpenseRuleRefVO::getHousePropertyId).collect(Collectors.toList());
                List<House> houseList = houseRepository.findByHousePropertyIdIn(housePropertyIds);
                List<HouseExpenseRuleRefVO> refs = new ArrayList<>();
                for (House house : houseList) {
                    HouseExpenseRuleRefVO ref = new HouseExpenseRuleRefVO();
                    ref.setHouseNature(house.getHouseNature());
                    ref.setCommunityId(house.getResidenceCommunityId());
                    ref.setBuildingNum(house.getBuildingNum());
                    ref.setUnit(house.getUnit());
                    ref.setHouseId(house.getId());
                    refs.add(ref);
                }
                ruleRefVO = refs;
                break;
            case 2:
                List<String> residenceCommunityIds = ruleRefVO.stream().map(HouseExpenseRuleRefVO::getCommunityId).collect(Collectors.toList());
                List<House> houseList1 = houseRepository.findByResidenceCommunityIdIn(residenceCommunityIds);
                List<HouseExpenseRuleRefVO> refs1 = new ArrayList<>();
                for (House house : houseList1) {
                    HouseExpenseRuleRefVO ref = new HouseExpenseRuleRefVO();
                    ref.setHouseNature(house.getHouseNature());
                    ref.setCommunityId(house.getResidenceCommunityId());
                    ref.setBuildingNum(house.getBuildingNum());
                    ref.setUnit(house.getUnit());
                    ref.setHouseId(house.getId());
                    refs1.add(ref);
                }
                ruleRefVO = refs1;
                break;
            case 3:
                List<House> houseList2 =new ArrayList<>();
                for(HouseExpenseRuleRefVO ref : ruleRefVO){
                    String residenceCommunityId = ref.getCommunityId();
                    Long buildingNum = ref.getBuildingNum();
                    houseList2.addAll(houseRepository.findByResidenceCommunityIdAndBuildingNum(residenceCommunityId,buildingNum));
                }

                List<HouseExpenseRuleRefVO> refs2 = new ArrayList<>();
                for (House house : houseList2) {
                    HouseExpenseRuleRefVO ref = new HouseExpenseRuleRefVO();
                    ref.setHouseNature(house.getHouseNature());
                    ref.setCommunityId(house.getResidenceCommunityId());
                    ref.setBuildingNum(house.getBuildingNum());
                    ref.setUnit(house.getUnit());
                    ref.setHouseId(house.getId());
                    refs2.add(ref);
                }
                ruleRefVO = refs2;
                break;
            case 4:
                List<House> houseList3 =new ArrayList<>();
                for (HouseExpenseRuleRefVO ref : ruleRefVO) {
                    String residenceCommunityId = ref.getCommunityId();
                    Long buildingNum = ref.getBuildingNum();
                    Long unit = ref.getUnit();
                    houseList3.addAll(houseRepository.findByResidenceCommunityIdAndBuildingNumAndUnit(residenceCommunityId, buildingNum, unit));
                }
                List<HouseExpenseRuleRefVO> refs3 = new ArrayList<>();
                for (House house : houseList3) {
                    HouseExpenseRuleRefVO ref = new HouseExpenseRuleRefVO();
                    ref.setHouseNature(house.getHouseNature());
                    ref.setCommunityId(house.getResidenceCommunityId());
                    ref.setBuildingNum(house.getBuildingNum());
                    ref.setUnit(house.getUnit());
                    ref.setHouseId(house.getId());
                    refs3.add(ref);
                }
                ruleRefVO = refs3;
                break;
        }

        Integer flag = ruleVO.getFlag();
        Integer day = ruleVO.getDay();
        Date startTimes = ruleVO.getStartTime();
        Integer dateFlag = ruleVO.getDateFlag();//时间标志：1开始时间 2结束时间
        if(dateFlag != null && dateFlag.equals(2)){
            startTimes = ruleVO.getEndTime();

        }
        Date closeTime = null;


        if (flag.equals(1)) {  // 1前 2后
            Calendar cal = Calendar.getInstance();
            cal.setTime(startTimes);
            cal.add(Calendar.DAY_OF_MONTH, -day);
            closeTime = cal.getTime();
        } else {
            Calendar cal = Calendar.getInstance();
            cal.setTime(startTimes);
            cal.add(Calendar.DAY_OF_MONTH, day);
            closeTime = cal.getTime();
        }


        ruleVO.setCloseTime(closeTime);
        ruleVO.setType(1); //类型：1公租房 2非公租房
        //过滤掉非公租房
        List<HouseExpenseRuleRefVO> refs = new ArrayList<>();
        for(HouseExpenseRuleRefVO ref : ruleRefVO){
            if(ref.getHouseNature().equals(1)){
                refs.add(ref);
            }
        }
        ruleRefVO = refs;

        List<String> failRoomNumberList = new ArrayList<>(); //账单已存在的房号

        if(!ruleVO.getChargeType().equals(8)) {
            //验证账单周期
            for (HouseExpenseRuleRefVO houseExpenseRuleRefVO : ruleRefVO) {
                List<HouseExpenseRuleRef> existHouseExpenseRule = houseExpenseRuleRefRepository.findByHouseId(houseExpenseRuleRefVO.getHouseId());
                for (HouseExpenseRuleRef houseExpenseRuleRef : existHouseExpenseRule) {
                    if(houseExpenseRuleRef.getRuleId().equals(ruleVO.getId())){
                        continue;
                    }
                    HouseExpenseBillRule houseExpenseBillRule = houseExpenseBillRuleRepository.findById(houseExpenseRuleRef.getRuleId());
                    //时间段不能有交集
                    if (houseExpenseBillRule.getChargeType().equals(ruleVO.getChargeType())) {
                        if ((ruleVO.getStartTime().getTime() < houseExpenseBillRule.getStartTime().getTime() && ruleVO.getEndTime().getTime() >= houseExpenseBillRule.getStartTime().getTime())
                                || (ruleVO.getStartTime().getTime() >= houseExpenseBillRule.getStartTime().getTime() && ruleVO.getEndTime().getTime() <= houseExpenseBillRule.getEndTime().getTime())
                                || (ruleVO.getStartTime().getTime() <= houseExpenseBillRule.getEndTime().getTime() && ruleVO.getEndTime().getTime() > houseExpenseBillRule.getEndTime().getTime())) {
                            //return ResultBean.failedResultWithMsg("周期内账单已存在");
                            House house = houseRepository.findById(houseExpenseRuleRefVO.getHouseId()).get();
                            failRoomNumberList.add(house.getRoomNumber());
                        }
                    }
                }
            }

        }else{  //租金
            //验证账单存在
            for (HouseExpenseRuleRefVO houseExpenseRuleRefVO : ruleRefVO) {
                List<HouseExpenseRuleRef> existHouseExpenseRule = houseExpenseRuleRefRepository.findByHouseId(houseExpenseRuleRefVO.getHouseId());
                for (HouseExpenseRuleRef houseExpenseRuleRef : existHouseExpenseRule) {
                    if(houseExpenseRuleRef.getRuleId().equals(ruleVO.getId())){
                        continue;
                    }
                    HouseExpenseBillRule houseExpenseBillRule = houseExpenseBillRuleRepository.findById(houseExpenseRuleRef.getRuleId());
                    if (houseExpenseBillRule.getChargeType().equals(ruleVO.getChargeType())) {
                        //return ResultBean.failedResultWithMsg("押金账单已存在");
                        House house = houseRepository.findById(houseExpenseRuleRefVO.getHouseId()).get();
                        failRoomNumberList.add(house.getRoomNumber());
                    }
                }
            }

            /*
             * 1.公租房选择的房屋，验证公租房备案状态为：已备案 ；已备案的公租房，才有合同和承租人
             * 2.只生成已完成的合同设置的计费方式和收费项目的计费方式一致的房子的账单规则
             */
            List<HouseExpenseRuleRefVO> refList = new ArrayList<>();
            HouseExpenseOther expense = houseExpenseOtherRepository.findById(ruleVO.getExpenseId());
            for (HouseExpenseRuleRefVO ref : ruleRefVO) {
                House house = houseRepository.findById(ref.getHouseId()).get();
                if(house.getRecordStatus().equals(1)){ //0未备案 1已备案
                    List<Contract> contractList = contractRepository.findByHouseId(ref.getHouseId());
                    if(contractList.size() > 0){
                        Contract contract = contractList.get(0);
                        if(contract.getPayType().equals(expense.getChargeMode())){
                            refList.add(ref);
                        }
                    }
                }
            }

            ruleRefVO = refList;

        }

        //返回失败房号
        if (failRoomNumberList.size() > 0) {
            return ResultBean.failedResultWithMsg(failRoomNumberList.toString() + "：账单已存在，无法生成账单");
        }

        //无房屋则不生成
        if(ruleRefVO.size() == 0){
            return ResultBean.failedResultWithMsg("无房屋生成！");
        }

        houseExpenseBillRuleRepository.deleteById(ruleVO.getId());
        houseExpenseRuleRefRepository.deleteByRuleId(ruleVO.getId());

        //生成账单
        ruleVO.setId("ZD" + KeyWorker.nextId());
        ruleVO.setNumber(ruleRefVO.size());
        ruleVO.setOperatorId(tokenRedisVo.getId());
        ruleVO.setCreateTime(new Date());
        HouseExpenseBillRule houseExpenseBillRule = new HouseExpenseBillRule();
        BeanUtils.copyProperties(ruleVO, houseExpenseBillRule);

        HouseExpenseBillRule save = houseExpenseBillRuleRepository.save(houseExpenseBillRule);
        if (save != null) {
            List<HouseExpenseRuleRef> ruleRefList = new ArrayList<>();
            ruleRefVO.forEach(h -> {
                HouseExpenseRuleRef houseExpenseRuleRef = new HouseExpenseRuleRef();
                BeanUtils.copyProperties(h, houseExpenseRuleRef);
                houseExpenseRuleRef.setRuleId(save.getId());
                ruleRefList.add(houseExpenseRuleRef);
            });

            houseExpenseRuleRefRepository.saveAll(ruleRefList);
        }

        return ResultBean.successfulResult(null);
    }

    //账单生成-删除账单
    public ResultBean<Object> deleteBill(String accessToken,String id){
        LOG.info("NewBillService deleteBill accessToken={},id={}", accessToken, id);

        if(StringUtils.isBlank(id)){
            return ResultBean.failedResultWithMsg("账单id为空");
        }

        houseExpenseBillRuleRepository.deleteById(id);
        houseExpenseRuleRefRepository.deleteByRuleId(id);

        return ResultBean.successfulResult(null);
    }

    /**
     * 账单生成-账单详情
     * @param accessToken 权限鉴定
     * @param id 账单id
     * @return
     */
    public ResultBean<Object> billInfo(String accessToken,String id){
        LOG.info("NewBillService  billInfo  accessToken={} ,id={}", accessToken,id);
        //判断账单ID是否为空
        if(StringUtils.isBlank(id)){
            return ResultBean.failedResultWithMsg("账单id为空");
        }
        //根据账单ID获取账单数据
        HouseExpenseBillRule rule = houseExpenseBillRuleRepository.findById(id);
        if(rule == null){
            return ResultBean.failedResultWithMsg("账单不存在");
        }

        HouseExpenseBillRuleVO vo = new HouseExpenseBillRuleVO();
        BeanUtils.copyProperties(rule,vo);
        //获取收费项目数据
        HouseExpenseOther houseExpenseOther = houseExpenseOtherRepository.findById(vo.getExpenseId());
        if(houseExpenseOther != null){
            vo.setExpenseName(houseExpenseOther.getName());
        }

        List<HouseExpenseRuleRef> ref = houseExpenseRuleRefRepository.findByRuleId(vo.getId());
        List<HouseExpenseRuleRefVO> refVO = new ArrayList<>();
        ref.forEach(r ->{
            HouseExpenseRuleRefVO v = new HouseExpenseRuleRefVO();
            BeanUtils.copyProperties(r,v);
            refVO.add(v);
        });

        vo.setHouseExpenseRuleRefVOList(refVO);
        List<String> houseIds = refVO.stream().map(HouseExpenseRuleRefVO::getHouseId).collect(Collectors.toList());

        List<Map<String, Object>> resultList = new ArrayList<>();//原始账单记录选中数据
        List<House> houseList = houseRepository.findByIdIn(houseIds);

        switch(vo.getScope()){ //账单范围选择[ 1物业、2小区、3楼栋、4单元、5房号]
            case 1:
                Map<Long, Object> tempMap = new HashMap<>();
                for (House house : houseList) {
                    Map<String, Object> map = new HashMap<>();
                    if(tempMap.containsKey(house.getHousePropertyId())){
                        continue;
                    }
                    map.put("housePropertyId",house.getHousePropertyId());
                    DepartmentHierarchy h = departmentHierarchyRepository.findByOrgId(house.getHousePropertyId());
                    map.put("housePropertyName",h.getName());
                    resultList.add(map);
                    tempMap.put(house.getHousePropertyId(),1);
                }
                break;
            case 2:
                Map<String, Object> tempMap1 = new HashMap<>();
                for (House house : houseList) {
                    Map<String, Object> map = new HashMap<>();
                    if(tempMap1.containsKey(house.getResidenceCommunityId())){
                        continue;
                    }
                    map.put("communityId",house.getResidenceCommunityId());
                    Community community = communityRepository.findById(house.getResidenceCommunityId()).get();
                    map.put("communityName",community.getName());
                    resultList.add(map);
                    tempMap1.put(house.getResidenceCommunityId(),1);
                }
                break;
            case 3:
                Map<String, Object> tempMap2 = new HashMap<>();
                for (House house : houseList) {
                    Map<String, Object> map = new HashMap<>();
                    if(tempMap2.containsKey(house.getResidenceCommunityId()+house.getBuildingNum())){
                        continue;
                    }
                    map.put("communityId",house.getResidenceCommunityId());
                    Community community = communityRepository.findById(house.getResidenceCommunityId()).get();
                    map.put("communityName",community.getName());

                    map.put("buildingNum",house.getBuildingNum());
                    CommunityBuild build = communityBuildRepository.findById(house.getBuildingNum()).get();
                    map.put("buildingNumName",build.getName());

                    resultList.add(map);
                    tempMap2.put(house.getResidenceCommunityId()+house.getBuildingNum(),1);
                }
                break;
            case 4:
                Map<String, Object> tempMap3 = new HashMap<>();
                for (House house : houseList) {
                    Map<String, Object> map = new HashMap<>();
                    if(tempMap3.containsKey(house.getResidenceCommunityId()+house.getBuildingNum()+house.getUnit())){
                        continue;
                    }
                    map.put("communityId",house.getResidenceCommunityId());
                    Community community = communityRepository.findById(house.getResidenceCommunityId()).get();
                    map.put("communityName",community.getName());

                    map.put("buildingNum",house.getBuildingNum());
                    CommunityBuild build = communityBuildRepository.findById(house.getBuildingNum()).get();
                    map.put("buildingNumName",build.getName());

                    map.put("unit",house.getUnit());
                    CommunityBuildUnit unit = communityBuildUnitRepository.findById(house.getUnit()).get();
                    map.put("unitName",unit.getName());

                    resultList.add(map);
                    tempMap3.put(house.getResidenceCommunityId()+house.getBuildingNum()+house.getUnit(),1);
                }
                break;
            case 5:
                for (House house : houseList) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("communityId",house.getResidenceCommunityId());
                    Community community = communityRepository.findById(house.getResidenceCommunityId()).get();
                    map.put("communityName",community.getName());

                    map.put("buildingNum",house.getBuildingNum());
                    CommunityBuild build = communityBuildRepository.findById(house.getBuildingNum()).get();
                    map.put("buildingNumName",build.getName());

                    map.put("unit",house.getUnit());
                    CommunityBuildUnit unit = communityBuildUnitRepository.findById(house.getUnit()).get();
                    map.put("unitName",unit.getName());

                    map.put("houseId",house.getId());
                    map.put("roomNumber",house.getRoomNumber());
                    map.put("houseNature", house.getHouseNature());
                    //过滤掉非公租房
                    if(!house.getHouseNature().equals(1)){
                        continue;
                    }
                    if(vo.getChargeType() == 8){  //收费项目(1水费 2电费 3物业费 4宽带费 5电视费 6煤气费 7暖气费 8租金 9押金)
                        /*
                         * 1.公租房选择的房屋，验证公租房备案状态为：已备案 ；已备案的公租房，才有合同和承租人
                         * 2.只生成已完成的合同设置的计费方式和收费项目的计费方式一致的房子的账单规则
                         */
                        HouseExpenseOther expense = houseExpenseOtherRepository.findById(vo.getExpenseId());
                        House h = houseRepository.findById(house.getId()).get();
                        if(h.getRecordStatus().equals(1)){ //0未备案 1已备案
                            List<Contract> contractList = contractRepository.findByHouseId(house.getId());
                            if(contractList.size() > 0){
                                Contract contract = contractList.get(0);
                                if(!contract.getPayType().equals(expense.getChargeMode())){
                                    continue;
                                }
                            }else{
                                continue;
                            }
                        }else{
                            continue;
                        }


                    }
                    resultList.add(map);
                }
                break;
        }

        vo.setResultList(resultList);

        return ResultBean.successfulResult(vo);

    }

    //账单生成-列表展示
    public ResultBean<Object> createBillList(String accessToken, Integer pageNumber, Integer pageSize, String id, String community) {
        LOG.info("NewBillService  createBillList  accessToken={} ", accessToken);

        return null;
    }

    /*
     *实现了点击账单生产按钮，查询收费项目
     */
    public ResultBean<Object> findByProjectList(String accessToken){
        //记录操作日志
        LOG.info("NewBillService  findByProjectList  accessToken={} ", accessToken);
        //查询数据
        List<NewProjectVO> list = this.projectList(accessToken,0,1000,null).getResultData().getData();
        //将数据返回给前端页面
        return ResultBean.successfulResult(list);
    }
    /**
     * 查询账单范围下的房源数据
     * @param accessToken 权限鉴定
     * @param pageNumber 当前页
     * @param pageSize 页数
     * @param scope 账单范围选择[ 1物业、2小区、3楼栋、4单元、5房号]
     * @param chargeType 收费项目(1水费 2电费 3物业费 4宽带费 5电视费 6煤气费 7暖气费 8租金 9押金)
     * @param expenseId 收费项目id
     * @param communityId 所属小区
     * @param buildingNum 楼栋Id
     * @param unitId 单元Id
     * @param roomNumber 房号
     * @return
     */
    //查询账单范围下的房源数据 [scope: 账单范围选择[ 1物业、2小区、3楼栋、4单元、5房号]]  , chargeType :收费项目(1水费 2电费 3物业费 4宽带费 5电视费 6煤气费 7暖气费 8租金 9押金) , expenseId :收费项目id
    public ResultBean<Object> findByHouseInfo(String accessToken,Integer pageNumber,Integer pageSize,Integer scope,Integer chargeType,String expenseId, String communityId, String buildingNum, String unitId, String roomNumber){
        LOG.info("NewBillService  findByHouseInfo  accessToken={} ", accessToken);
        List<Map<String, Object>> list = appCommunityService.findCommunity(accessToken).getResultData();
        //获取所有小区ID
        List<String> communityIds =new ArrayList<>();
        if (list != null && !list.isEmpty()) {
            communityIds = list.stream().map(map -> {
                String comId = map.get("communityId").toString();
                return comId;
            }).collect(Collectors.toList());
        }
        if(communityIds.size() == 0){
            return ResultBean.successfulResult(null);
        }

        List<Map<String, Object>> resultList = new ArrayList<>();
        //获取公租房数据
        List<House> houseList = new ArrayList<>();
        if(StringUtils.isBlank(communityId)){
            houseList = houseRepository.findByResidenceCommunityIdIn(communityIds);
        }else{
            houseList = houseRepository.findByResidenceCommunityId(communityId);
            if(StringUtils.isNotBlank(buildingNum)){
                houseList = houseRepository.findByResidenceCommunityIdAndBuildingNum(communityId,Long.valueOf(buildingNum));
                if(StringUtils.isNotBlank(unitId)){
                    houseList = houseRepository.findByResidenceCommunityIdAndBuildingNumAndUnit(communityId,Long.valueOf(buildingNum),Long.valueOf(unitId));
                    if(StringUtils.isNotBlank(roomNumber)){
                        houseList = houseRepository.findByResidenceCommunityIdAndBuildingNumAndUnitAndRoomNumber(communityId,Long.valueOf(buildingNum),Long.valueOf(unitId),roomNumber);
                    }
                }
            }
        }

        switch(scope){ //账单范围选择[ 1物业、2小区、3楼栋、4单元、5房号]，根据不同业务范围设置不同数据
            case 1:
                Map<Long, Object> tempMap = new HashMap<>();
                //遍历获取公租房数据
                for (House house : houseList) {
                    Map<String, Object> map = new HashMap<>();
                    if(tempMap.containsKey(house.getHousePropertyId())){
                        continue;
                    }
                    map.put("housePropertyId",house.getHousePropertyId());
                    DepartmentHierarchy h = departmentHierarchyRepository.findByOrgId(house.getHousePropertyId());
                    map.put("housePropertyName",h.getName());
                    resultList.add(map);
                    tempMap.put(house.getHousePropertyId(),1);
                }
                break;
            case 2:
                Map<String, Object> tempMap1 = new HashMap<>();
                for (House house : houseList) {
                    Map<String, Object> map = new HashMap<>();
                    if(tempMap1.containsKey(house.getResidenceCommunityId())){
                        continue;
                    }
                    map.put("communityId",house.getResidenceCommunityId());
                    Community community = communityRepository.findById(house.getResidenceCommunityId()).get();
                    map.put("communityName",community.getName());
                    resultList.add(map);
                    tempMap1.put(house.getResidenceCommunityId(),1);
                }
                break;
            case 3:
                Map<String, Object> tempMap2 = new HashMap<>();
                for (House house : houseList) {
                    Map<String, Object> map = new HashMap<>();
                    if(tempMap2.containsKey(house.getResidenceCommunityId()+house.getBuildingNum())){
                        continue;
                    }
                    map.put("communityId",house.getResidenceCommunityId());
                    Community community = communityRepository.findById(house.getResidenceCommunityId()).get();
                    map.put("communityName",community.getName());

                    map.put("buildingNum",house.getBuildingNum());
                    CommunityBuild build = communityBuildRepository.findById(house.getBuildingNum()).get();
                    map.put("buildingNumName",build.getName());

                    resultList.add(map);
                    tempMap2.put(house.getResidenceCommunityId()+house.getBuildingNum(),1);
                }
                break;
            case 4:
                Map<String, Object> tempMap3 = new HashMap<>();
                for (House house : houseList) {
                    Map<String, Object> map = new HashMap<>();
                    if(tempMap3.containsKey(house.getResidenceCommunityId()+house.getBuildingNum()+house.getUnit())){
                        continue;
                    }
                    map.put("communityId",house.getResidenceCommunityId());
                    Community community = communityRepository.findById(house.getResidenceCommunityId()).get();
                    map.put("communityName",community.getName());

                    map.put("buildingNum",house.getBuildingNum());
                    CommunityBuild build = communityBuildRepository.findById(house.getBuildingNum()).get();
                    map.put("buildingNumName",build.getName());

                    map.put("unit",house.getUnit());
                    CommunityBuildUnit unit = communityBuildUnitRepository.findById(house.getUnit()).get();
                    map.put("unitName",unit.getName());

                    resultList.add(map);
                    tempMap3.put(house.getResidenceCommunityId()+house.getBuildingNum()+house.getUnit(),1);
                }
                break;
            case 5:
                for (House house : houseList) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("communityId",house.getResidenceCommunityId());
                    Community community = communityRepository.findById(house.getResidenceCommunityId()).get();
                    map.put("communityName",community.getName());

                    map.put("buildingNum",house.getBuildingNum());
                    CommunityBuild build = communityBuildRepository.findById(house.getBuildingNum()).get();
                    map.put("buildingNumName",build.getName());

                    map.put("unit",house.getUnit());
                    CommunityBuildUnit unit = communityBuildUnitRepository.findById(house.getUnit()).get();
                    map.put("unitName",unit.getName());

                    map.put("houseId",house.getId());
                    map.put("roomNumber",house.getRoomNumber());
                    map.put("houseNature", house.getHouseNature());
                    //过滤掉非公租房
                    if(!house.getHouseNature().equals(1)){
                        continue;
                    }
                    if(chargeType == 8){  //收费项目(1水费 2电费 3物业费 4宽带费 5电视费 6煤气费 7暖气费 8租金 9押金)
                        /*
                         * 1.公租房选择的房屋，验证公租房备案状态为：已备案 ；已备案的公租房，才有合同和承租人
                         * 2.只生成已完成的合同设置的计费方式和收费项目的计费方式一致的房子的账单规则
                         */
                        HouseExpenseOther expense = houseExpenseOtherRepository.findById(expenseId);
                        House h = houseRepository.findById(house.getId()).get();
                        if(h.getRecordStatus().equals(1)){ //0未备案 1已备案
                            List<Contract> contractList = contractRepository.findByHouseId(house.getId());
                            if(contractList.size() > 0){
                                Contract contract = contractList.get(0);
                                if(!contract.getPayType().equals(expense.getChargeMode())){
                                    continue;
                                }
                            }else{
                                continue;
                            }
                        }else{
                            continue;
                        }


                    }
                    resultList.add(map);
                }
                break;
        }

        pageNumber += 1;
        //分页数据
        List<Map<String, Object>> pageList = new ArrayList<>();
        //返回结果
        Map<String, Object> resultMap =new HashMap<>();

        Integer count = resultList.size(); // 记录总数
        Integer pageCount = 0; // 页数
        if (count % pageSize == 0) {
            pageCount = count / pageSize;
        } else {
            pageCount = count / pageSize + 1;
        }
        int fromIndex = 0; // 开始索引
        int toIndex = 0; // 结束索引

        if(pageCount.equals(0)){
            pageCount = 1;
        }
        //实现翻页
        if ( !pageNumber.equals(pageCount)) {
            fromIndex = (pageNumber - 1) * pageSize;
            toIndex = fromIndex + pageSize;
        } else {
            fromIndex = (pageNumber - 1) * pageSize;
            toIndex = count;
        }

        pageList = resultList.subList(fromIndex, toIndex);

        resultMap.put("total",count);
        resultMap.put("data", pageList);
        //返回数据给前端页面
        return ResultBean.successfulResult(resultMap);
    }







}
